/*
 * Copyright 2013 Sigurd Randoll <srandoll@digiway.de>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.digiway.rapidbreeze.server.migrate.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Logger;

/**
 *
 * @author Sigurd Randoll <srandoll@digiway.de>
 */
public class StorageProviderDefault {
    
    private static Properties props = null;
    public static final String HOST_ACCOUNTS_FILE = "/HosterAccounts.properties";
    private static final Logger LOG = Logger.getLogger(StorageProviderDefault.class.getName());
    
    private static void loadProperties() {
        if (props == null) {
            try {
                InputStream is = StorageProviderDefault.class.getResourceAsStream(HOST_ACCOUNTS_FILE);
                props = new Properties();
                props.load(is);
            } catch (IOException ex) {
                LOG.info("There is no default " + HOST_ACCOUNTS_FILE + " file. Ignorning default data.");
            }
        }
    }
    
    public static String getUsername(Class<?> storageDownloadClass) {
        loadProperties();
        if (props != null) {
            return props.getProperty(storageDownloadClass.getSimpleName() + "_username");
        }
        return null;
    }
    
    public static String getPassword(Class<?> storageDownloadClass) {
        loadProperties();
        if (props != null) {
            return props.getProperty(storageDownloadClass.getSimpleName() + "_password");
        }
        return null;
    }
}
